#include "H264MediaCodecEncoder.h"

const AVCodec *H264MediaCodecEncoder::findCodec(EncoderParam &encoderParam) {
  return avcodec_find_encoder_by_name("h264_mediacodec");
}

int32_t
H264MediaCodecEncoder::initContextParam(AVCodecContext *pCodecCtx, EncoderParam &encoderParam) {
  pCodecCtx->width = encoderParam.width;
  pCodecCtx->height = encoderParam.height;
  pCodecCtx->bit_rate = encoderParam.bitRate;
  pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
  //编码器上下文的时间基
  pCodecCtx->time_base = av_make_q(1, encoderParam.frameRate);
  //编码器上下文的帧率
  pCodecCtx->framerate = av_make_q(encoderParam.frameRate, 1);

  pCodecCtx->gop_size = 10;
  pCodecCtx->max_b_frames = 0;

  //针对x264的设置
  pCodecCtx->profile = FF_PROFILE_H264_MAIN;
  av_opt_set(pCodecCtx->priv_data, "preset", "slow", 0);

  return SUCCESS;
}

MediaType H264MediaCodecEncoder::getMediaType() {
  return MediaType_Video;
}

const char *H264MediaCodecEncoder::getClassName() {
  return "H264MediaCodecEncoder";
}

void H264MediaCodecEncoder::toString() {
  LOG_TEST("H264MediaCodecEncoder()")
}